<script>
  function fn1() { return 1}
  async function fn2() { return 1}
  function fn3() {
    return new Promise((resolve) => resolve(1))
  }
  function fn4() {
    return Promise.resolve(1)
  }
  async function fnError1() {
    throw 'error'
  }
  async function fn5() {
    return Promise.resolve(1)
  }

  console.log(fn1())
  console.log(fn2())
  console.log(fn3())
  console.log(fn4())
  console.log(Promise.resolve().then(() => 1))
  // console.log(fnError1())
  console.log(fn5())

  function delay(ms) {
    return new Promise(function (resolve) {
      setTimeout(() => resolve(), ms)
    })
  }

  async function fn6() {
    console.log('fn6 开始')
    // const i = await Promise.resolve(1)
    // const i = await delay(2000).then(() => 1)
    try{
      const i = await delay(2000).then(() => { throw 1})
      console.log(i)
    } catch(e) {
      console.log('报错了')
    }
  }


</script>

<script type="module">
import {ajax} from './ajax.js'

let json = null
ajax('./data.json').then(v => json = v)
console.log('json=', json)

let json2 = await ajax('./data.json')
console.log('json2=', json2)

if (true) {
  await 1
}

function fn2() {
  // await 1
}
// fn2()
</script>